﻿Namespace('FaScript.Models');

FaScript.Models.defineClass('[Name]Model', function () {
    /// <summary>实体对象</summary>
    /// <param name="modelName" type="String">名称</param>
    /// <param name="controller" type="String">控制器</param>
    
    var _properties = {[Properties]};

    this.RegistEmberModel = function (app) {
        /// <summary>注册Ember实体</summary>
        /// <param name="app" type="Object">EmberApplication</param>

        var model = {};
        $.each(_properties, function (n, d) {
            if (n.toLocaleLowerCase() == 'id') return true;
            model[n] = DS.attr(d.type);
        });

        app.[Name] = DS.Model.extend(model);
    };

    this.toJSON = function () {
        var json = {};
        $.each(_properties, function (n, d) {
            json[n] = d.value;
        });
    };

    $.each(_properties, function (n, d) {
        Object.defineProperty(this, n, {
            get: function () {
                return _properties[n].value;
            },
            set: function (val) {
                _properties[n].value = val;
            }
        });
    });
});